package org.martin.snsrs.client;

import org.martin.snsrs.client.manager.Session;
import org.martin.snsrs.client.util.SystemUiHider;

import android.annotation.TargetApi;
import android.app.Activity;
import android.content.Intent;
import android.os.AsyncTask;
import android.os.Build;
import android.os.Bundle;
import android.os.Handler;
import android.view.MotionEvent;
import android.view.View;

public class StartActivity extends Activity {
	private Handler handler;
	
	private boolean isLogin;
	protected void onCreate(Bundle savedBundle){
		super.onCreate(savedBundle);
		handler = new Handler();
		loadData();
		handler.postDelayed(new Runnable() {
			
			@Override
			public void run() {
				if(StartActivity.this.isLogin)
					goToMainActivity();
				else {
					goToLoginActivity();
				}
			}
		}, 500L);
	}
	private void loadData(){
		AsyncTask<Object, Object, Object> task = new AsyncTask<Object, Object, Object>(){
			
			@Override
			protected Object doInBackground(Object... params) {
				Session session = Session.get(StartActivity.this);
				if(session == null)
					isLogin = false;
				else {
					isLogin = true;
				}
				return null;
			}
			
		};
		task.execute(new Object[0]);
	}
	
	public void goToMainActivity(){
		Intent intent = new Intent();
		intent.setClass(this, MainActivity.class);
		startActivity(intent);
		finish();
	}
	
	public void goToLoginActivity(){
		Intent intent = new Intent();
		intent.setClass(this, LoginActivity.class);
		startActivity(intent);
		finish();
	}
}
